package hd.util.adapter.pager;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * ViewPager的Adapter
 * <p/>
 * Created by Haidy on 14/11/29.
 */
public class BasePagerAdapter extends PagerAdapter {
    private final List<View> viewList;

    public BasePagerAdapter(List<View> viewList) {
        this.viewList = viewList;
    }

    public View getView(int index) {
        return viewList.get(index);
    }

    @Override
    public int getCount() {
        return viewList.size();
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        container.addView(viewList.get(position), 0);
        return viewList.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewList.get(position));
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }
}
